package com.exercise.api.web;

import com.exercise.commons.vo.ProductDetail;
import com.exercise.commons.vo.Result;
import com.exercise.api.feign.ProductDetailApiFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api/productdetail")
public class ProductDetailApi {

    @Autowired
    private ProductDetailApiFeign productDetailApiFeign;
    /**
     * 根据商品Id获取商品详情
     *
     */
    @GetMapping("/productId")
    @ResponseBody
    @CrossOrigin
    public Result<List<ProductDetail>> getProductDetails(@RequestParam("productId") String productId) {

        Result<List<ProductDetail>> result = new Result<>();
        List<ProductDetail> productDetails = productDetailApiFeign.getByProductId(productId);
        result.setData(productDetails);
        result.setSuccess(true);
        return result;

    }
}
